package com.sl.biz.modular.ai.dao.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sl.biz.modular.ai.dao.domain.entity.AiConfigDO;
import com.sl.biz.modular.ai.dao.mapper.AiConfigMapper;
import com.sl.biz.modular.ai.dao.service.AiConfigDaoService;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class AiConfigDaoServiceImpl extends ServiceImpl<AiConfigMapper, AiConfigDO> implements AiConfigDaoService {

    @Override
    public List<AiConfigDO> queryByCondition(AiConfigDO jobConfigDO) {
        LambdaQueryWrapper<AiConfigDO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(ObjectUtil.isNotNull(jobConfigDO.getDisableFlag()), AiConfigDO::getDisableFlag, jobConfigDO.getDisableFlag());
        lambdaQueryWrapper.eq(StrUtil.isNotBlank(jobConfigDO.getGroupId()), AiConfigDO::getGroupId, jobConfigDO.getGroupId());
        return super.list(lambdaQueryWrapper);
    }

    @Override
    public Boolean updateDisableFlag(AiConfigDO assertUserUse) {
        LambdaUpdateWrapper<AiConfigDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        lambdaUpdateWrapper.set(AiConfigDO::getDisableFlag, assertUserUse.getDisableFlag());
        lambdaUpdateWrapper.eq(AiConfigDO::getId, assertUserUse.getId());
        return super.update(lambdaUpdateWrapper);
    }

    @Override
    public AiConfigDO getByCode(String aiCode) {
        LambdaQueryWrapper<AiConfigDO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(AiConfigDO::getAiCode, aiCode);
        return super.getOne(lambdaQueryWrapper);
    }
}
